package com.kamistoat.meimeichat.meimeichatserverapplication.netty;

import com.kamistoat.meimeichat.meimeichatserverapplication.netty.handlers.*;
import com.kamistoat.meimeichatserveraggrement.codec.ObjDecoder;
import com.kamistoat.meimeichatserveraggrement.codec.ObjEncoder;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.SocketChannel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * NettyServer的 ChannelInitializer.
 */
@Component
public class NettyServerChannelInitializer extends ChannelInitializer<SocketChannel> {
    @Autowired
    AddFriendHandlerServer addFriendHandlerServer;
    @Autowired
    DelTalkHandlerServer delTalkHandlerServer;
    @Autowired
    LoginHandlerServer loginHandlerServer;
    @Autowired
    MsgGroupHandlerServer msgGroupHandlerServer;
    @Autowired
    MsgHandlerServer msgHandlerServer;
    @Autowired
    ReconnectHandlerServer reconnectHandlerServer;
    @Autowired
    SearchFriendHandlerServer searchFriendHandlerServer;
    @Autowired
    TalkNoticeHandlerServer talkNoticeHandlerServer;
    @Autowired
    MsgRoamingHandlerServer msgRoamingHandlerServer;

    @Override
    protected void initChannel(SocketChannel socketChannel) throws Exception {
        //对象传输处理[解码]
        socketChannel.pipeline().addLast(new ObjDecoder());
        // 在管道中添加我们自己的接收数据实现方法
        socketChannel.pipeline().addLast(addFriendHandlerServer);
        socketChannel.pipeline().addLast(delTalkHandlerServer);
        socketChannel.pipeline().addLast(loginHandlerServer);
        socketChannel.pipeline().addLast(msgGroupHandlerServer);
        socketChannel.pipeline().addLast(msgHandlerServer);
        socketChannel.pipeline().addLast(reconnectHandlerServer);
        socketChannel.pipeline().addLast(searchFriendHandlerServer);
        socketChannel.pipeline().addLast(talkNoticeHandlerServer);
        socketChannel.pipeline().addLast(msgRoamingHandlerServer);
        //对象传输处理[编码]
        socketChannel.pipeline().addLast(new ObjEncoder());
    }
}
